package Graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Set;

import javax.swing.JPanel;

import Game.GameController;
import Game.GameModel;
import Game.Platform;
import Game.Player;
import Game.Position;

public class GamePanel extends JPanel {
	private GameController controller;
										//I'm just gonna go ahead and put this here, this is due soon, no time for fancy MVC architectures
										//just don't do things that'll break the code!!!  Please...
	// the MVC police have taken the platforms in for questioning
	
	public GamePanel(GameController controller) {
		this.controller = controller;
	}
	
	public void paintComponent(Graphics g) {
		GameModel model = controller.getModel();
		Set<Platform> platforms = model.getPlatforms();
		Graphics2D g2 = (Graphics2D)g;
		Position playerPosition = model.getPlayerPosition();
		int length = model.getPlayerLength();
		
		g2.setColor(new Color(255, 0, 0));
		g2.fillRect(playerPosition.getRoundedX(), playerPosition.getRoundedY(), length, length);
		
		if(platforms != null) {
			g2.setColor(new Color(0, 0, 0));
			//g2.fillRect(0, 310, 400, 25);
			
			for(Platform platform: platforms) {
				Position pos = platform.getPosition();
				
				g2.fillRect(pos.getRoundedX(), pos.getRoundedY(), (int) platform.getWidth(), (int) platform.getHeight());
			}
		}
		
		drawDebug(g2);
	}
	
	private void drawDebug(Graphics2D g2) {
		GameModel model = controller.getModel();
		
		g2.drawString("Best Score: " + model.getBestScore() , 0, 15);
		g2.drawString("Score: " + model.getScore() , 0, 30);
		
	}
}
